package com.sgb.kjwl.view.ui.activity.self.publish;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import androidx.fragment.app.Fragment;

import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityPackersListBinding;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.self.PackersPublishEvent;
import com.sgb.kjwl.view.ui.fragment.self.PackersStateFragment;
import com.swgk.core.recyclerview.adapter.SlidingFragmentPagerAdapter;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;

@Deprecated
public class PackersListActivity extends AppActivity {
    private ActivityPackersListBinding binding;
    private String[] titles = {"全部", "已上架", "已下架"};
    private ArrayList<Fragment> mFragments;


    public static void start(Context context) {
        start(context, null);
    }

    public static void start(Context context, Intent extras) {
        Intent intent = new Intent();
        intent.setClass(context, PackersListActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        if (extras != null) {
            intent.putExtras(extras);
        }
        context.startActivity(intent);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(PackersListActivity.this, R.layout.activity_packers_list);
        binding.backView.setOnClickListener(this);
        binding.publishView.setOnClickListener(this);
        mFragments = new ArrayList<Fragment>();
        mFragments.add(PackersStateFragment.newInstance(""));
        mFragments.add(PackersStateFragment.newInstance("1"));
        mFragments.add(PackersStateFragment.newInstance("2"));
        SlidingFragmentPagerAdapter mAdapetr = new SlidingFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titles);
        binding.viewpager.setAdapter(mAdapetr);
        binding.viewpager.setOffscreenPageLimit(2);
        binding.tablayout.setupWithViewPager(binding.viewpager);
    }

    @Override
    protected void init() {

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back_view:
                finish();
                break;
            case R.id.publish_view:
                EventBus.getDefault().postSticky(PackersPublishEvent.make().setMessageTag(EventConstant.EVENT_PUBLISH_PACKERS_PUBLISH));
                PackersPublishActivity.start(this);
                break;
        }
    }
}

